<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% if can_do @account, @current_user, :read_course_list %>
  <% term_count =  @root_account.enrollment_terms.active.count %>
  <% if term_count > 1 || @associated_courses_count > 0  %>
    <h2>{{#t}}Course Filtering{{/t}}</h2>
    <div class="rs-margin-bottom">
      <form method="get">
        <% if term_count > 1 %>
          <label for="enrollment_term_id"><%= before_label(t(:enrollment_term_label, "Show courses from the term")) %></label><br />
          {{> views/shared/enrollment_term_select}}
          <br />
        <% end %>
        <% if @query.present? %><input name="course[name]" type="hidden" value="<%= @query %>" /><% end %>
        <input name="focus" type="hidden" value="filter_button"/>
        <input name="hide_enrollmentless_courses" type="hidden" value="0" />
        <input id="enroll_filter_checkbox" name="hide_enrollmentless_courses" type="checkbox" value="1" <% if params[:hide_enrollmentless_courses] == "1" %>checked="checked"<% end %>/>
        <label for="enroll_filter_checkbox">{{#t}}Hide enrollmentless courses{{/t}}</label>
        <% if master_courses? %>
        <br>
        <input id="mc_filter_checkbox" name="only_master_courses" type="checkbox" value="1" <% if params[:only_master_courses] == "1" %>checked="checked"<% end %>/>
        <label for="mc_filter_checkbox">{{#t}}Show only blueprint courses{{/t}}</label>
        <% end %>
        <br />
        <span aria-hidden="true" class="screenreader-only" id="course-sort-description">
          {{#t}}Sort courses{{/t}}
        </span>
        <label for="courses_sort_order">{{#t}}Sort:{{/t}}</label>
        <select name="courses_sort_order" aria-labelledby="course-sort-description">
          <% @courses_sort_orders.each do |order| %>
            <option value="<%= order[:key] %>" <%= "selected" if @current_user.preferences[:course_sort] == order[:key] %>>
              <%= order[:label].call %>
            </option>
          <% end %>
        </select>
        <br />
        <button id='filter_button' class='btn filter_button'>{{#t}}Filter{{/t}}</button>
      </form>
    </div>

    <% if @associated_courses_count > 0 %>
      <% js_bundle :account_search %>
      <h2 id="course_name_label">{{#t}}Find a Course{{/t}}</h2>
      <div class="rs-margin-bottom">
        <%= form_for :course, :url => account_courses_path(@account), :html => {:id => "new_course", :class => "ic-Form-control account_search_form", :method => :get} do |f| -%>
          <div class="ic-Input-group">
            <input name="focus" type="hidden" value="course_name"/>
            <input id="course_name"
                   type="text"
                   name="course[name]"
                   class="ic-Input"
                   value="<%= @query %>"
                   data-autocomplete-source="<%= account_courses_path(@account) %>"
                   aria-labelledby="course_name_label"
            />
            <button class='Button'>{{#t}}Go{{/t}}</button>
          </div>
        <%- end -%>
      </div>
    <% end %>
  <% end %>
<% end %>
<% js_bundle :account_show %>
<% js_bundle :focus_helper %>

{{> views/shared/accounts_right_side_shared}}
{{> views/add_course_or_user}}
